<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Dubbo</title>
    <script type="text/javascript" src="jquery-easyui-1.4.5/jquery.min.js"></script>
    <script type="text/javascript" src="jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/public.css">
    <script src="js/function/sosowx.js?v=0.2"></script>
    <script type="text/javascript">
        var dataId;
        var index;
        var model;
        /**
         * 初始模板
         */
        function init() {
            dataId = GetQueryString("id");
            $.ajax({
                type: "GET",
                url: "/metadataQuery/getModelList/" + dataId,
                async: true,
                dataType: 'json',
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    model = data;
                    $("#modelList").html("");
                    for (i = 0; i < data.length; i++) {
                        var li = "<li><a href=\"#\" onclick=\"initList(" + i + ")\">" + data[i].model_name + " </a></li>";
                        $("#modelList").append(li);
                    }
                }
            });
        }

        /**
         * 初始化主表和列表
         */
        function initList(i) {
            index = i;
            $("#mname").val(model[index].model_name);$("#dfilter").val(model[index].model_default_filter);
            getLList();
            getMainList();
        }

        /**
         * 获取显示列表
         */
        function getLList() {
            $.ajax({
                type: "GET",
                url: "/metadataQuery/getList/" + model[index].model_id,
                async: true,
                dataType: 'json',
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    $("#llist").html(" <thead> <td>显示名称</td> <td>字段名</td> </thead>");
                    for (i = 0; i < data.length; i++) {
                        var table = "<tr>";
                        table += "<td>" + data[i].list_show_name + "</td>"
                                + "<td>" + data[i].list_column_name + "</td>";
                        table += "</tr>";
                        $("#llist").append(table);
                    }
                }
            });
        }

        /**
         * 获取主表
         */
        function getMainList() {
            $.ajax({
                type: "GET",
                url: "/metadataQuery/getMainList/" + model[index].model_id,
                async: true,
                dataType: 'json',
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    $("#mainList").html(" <thead> <td>显示名称</td> <td>数据源字段主键</td> <td>默认值</td> </thead>");
                    for (i = 0; i < data.length; i++) {
                        var table = "<tr>";
                        table += "<td>" + data[i].main_show_name + "</td>"
                                + "<td>" + data[i].column_id + "</td>"
                                + "<td>" + data[i].main_default + "</td>";
                        table += "</tr>";
                        $("#mainList").append(table);
                    }
                }
            });
        }

        /**
         * 保存模板
         */
        function saveModel() {
            var datas = {
                model_name: $("#mname").val(),
                data_id: dataId,
                model_default_filter: $("#dfilter").val(),
            }
            $.ajax({
                type: "POST",
                url: "/metadataNew/insert/" +Table.META_MODEL,
                async: true,
                dataType: 'json',
                data: JSON.stringify(datas),
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function () {
                    init();
                }
            });
        }

        /**
         * 保存列表
         */
        function saveList() {

            var datas = {
                sName: $("#lsname").val(),
                cName: $("#lcname").val(),
                modelId: model[index].model_id
            }
            $.ajax({
                type: "POST",
                url: "/metadataNew/insert/"+Table.META_LIST,
                async: true,
                dataType: 'json',
                data: JSON.stringify(datas),
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    getLList();
                }
            });
        }

        /**
         * 保存主表
         */
        function saveMain() {
            var datas = {
                name: $("#msname").val(),
                columnId: $("#mcolumn").val(),
                default: $("#default").val(),
                modelId: model[index].model_id,
            }
            $.ajax({
                type: "POST",
                url: "/metadataNew/insert/"+Table.META_MAIN,
                async: true,
                dataType: 'json',
                data: JSON.stringify(datas),
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    getMainList();
                }
            });
        }

        function goToFAD() {
            window.location.href = "updateFilterAndDetailed.html?id=" + model[index].model_id;
        }

    </script>
</head>
<body onload="init();">
<div style="width: auto; float: left">
    <h6>模板维护列表</h6>
    模板名称：<input type="text" id="mname">
    默认过滤条件：<input type="text" id="dfilter"><input type="button" value="新增模板" onclick="saveModel()">

    <p/>
    <ul id="modelList">
    </ul>
</div>
<div>
    <a href="#" onclick="goToFAD()">维护过滤条件与明细表</a>
    <h6>显示列表维护</h6>

    <p/>
    显示名：<input type="text" id="lsname">字段名：<input type="text" id="lcname"><input type="button" value="新增列表字段"
                                                                                 onclick="saveList()">

    <p/>
    <table id="llist">
        <thead>
        <td>显示名称</td>
        <td>字段名</td>
        </thead>
    </table>
    <h6>主表维护</h6>

    <p/>
    显示名：<input type="text" id="msname">数据源字段ID：<input type="text" id="mcolumn">默认值：<input type="text" id="default">

    <p/>
    <input type="button" value="新增主表字段" onclick="saveMain()">

    <p/>
    <table id="mainList">
        <thead>
        <td>显示名称</td>
        <td>数据源字段主键</td>
        <td>默认值</td>
        </thead>
    </table>
</div>
</body>
</html>